using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XFGameFramework;
using XFGameFramework.ArchiveSystem;

public class UserDataController : Controller
{
    public Resolution[] resolutions = Screen.resolutions;
    public override void OnInit()
    {
        base.OnInit();
        if (GetUserModel() == null)
        {
            ArchiveManager.Create<UserModel>(12);
            Debug.Log("游戏第一次启动，创建了一个UserModel");
        }

    }
    public void applysavedata()
    {
        UserModel userModel = GetUserModel();
        if (userModel!= null)
        {
            int width = resolutions[userModel.ScreenResolutionIndex].width;
            int height = resolutions[userModel.ScreenResolutionIndex].height;
            Screen.SetResolution(width, height, userModel.isFullScreen);
            AudioController music = AudioPlayer.GetAuidoController("Music");
            AudioController sound = AudioPlayer.GetAuidoController("Sound");
            music.Volume = userModel.musicVolume;
            sound.Volume = userModel.soundVolume;

        }
    }
    public void CreateUserModel()
    {
        ArchiveManager.Create<UserModel>(12);
    }
    public void DeleteUserModel()
    {
        ArchiveManager.Delete(12);
    }

    public UserModel GetUserModel()
    {
        return ArchiveManager.Get<UserModel>(12);
    }
    public void SaveUserModel()
    {
        ArchiveManager.Save(12);
    }
}
